<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>点击获取search参数</button>
    <div class="container"></div>
    <script>
      var btn = document.querySelector("button");
      var containerEle = document.querySelector(".container");
      btn.onclick = function () {
        // decodeURI把中文乱码转回中文显示；
        var str = decodeURI(window.location.search);
        console.log(str);
        var obj = fn(str);
        // console.log(obj);
        var htmlStr = `<p>账号是:${obj.账号} 密码是:${obj.密码}</p>`;
        containerEle.innerHTML = htmlStr;
      };
      function fn(str) {
        str = str.substr(1);
        var arr = str.split("&");
        var obj = {};
        arr.forEach(function (item) {
          var newarr = item.split("=");
          obj[newarr[0]] = newarr[1];
        });
        return obj;
      }
    </script>
  </body>
</html>
